#{extends 'layout.html' /}
#{set title:messages.get('crud.list.title', '图书列表') /}
<script src="@{'/public/javascripts/jquery-1.6.4.min.js'}" type="text/javascript"></script>
<link rel="stylesheet" href="@{'/public/stylesheets/zTree/zTreeStyle.css'}" type="text/css">
<script type="text/javascript" src="@{'/public/javascripts/zTree/jquery.ztree.core-3.1.js'}"></script>
<script type="text/javascript" src="@{'/public/javascripts/zTree/jquery.ztree.excheck-3.1.js'}"></script>
<script type="text/javascript" src="@{'/public/javascripts/zTree/jquery.ztree.exedit-3.1.js'}"></script>
<SCRIPT type="text/javascript">
  		var treeNodeObj ;
		<!--
		var setting = {
			async: {
				enable: true,
				url:"/controllers/BookTypeaction.tree",
				autoParam:["id", "name=n", "level=lv"],
				otherParam:{"otherParam":"zTreeAsyncTest"},
				dataFilter: filter
			},
			view: {expandSpeed:"",
				addHoverDom: addHoverDom,
				removeHoverDom: removeHoverDom,
				selectedMulti: false
			},
			edit: {
				enable: true
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				beforeRemove: beforeRemove,
				beforeRename: beforeRename,
				onClick: onClick
			}
		};

		function filter(treeId, parentNode, childNodes) {
			if (!childNodes) return null;
			for (var i=0, l=childNodes.length; i<l; i++) {
				childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
			}
			return childNodes;
		}
		function onClick(event, treeId, treeNode, clickFlag) {
			var eid = treeNode.id;
			window.parent.f.post({
				id:'#sys_topic',
				isBox:false,
				data:"eid="+eid+"&",
				buts:window.parent.buts
			});
		}	
		function beforeRemove(treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("treeDemo");
			zTree.selectNode(treeNode);
			var fag = confirm("确认删除 题库 -- " + treeNode.name + " 吗？当前操作将删除当前题库下的所有内容");
			if(fag){
				$.ajax({
					url:'',
					type:'post',
					data:'eid='+treeNode.id,
					success:function(e){
						if(e == "0"){
							window.location = "";
						}else if(e == "1"){
							alert("删除成功！");
						}else{
							alert("删除失败！");
						}
					}
				});
			}
			return fag;
		}		
		function beforeRename(treeId, treeNode, newName) {
			if (newName.length == 0) {
				alert("题库名称不能为空.");
				return false;
			}
			return true;
		}

		var newCount = 1;
		function addHoverDom(treeId, treeNode) {
			treeNodeObj = treeNode;
			var sObj = $("#" + treeNode.tId + "_span");
			if ($("#addBtn_"+treeNode.id).length>0) return;
			var addStr = "<button type='button' class='add' id='addBtn_" + treeNode.id
				+ "' title='添加题库' onfocus='this.blur();'></button>";
			sObj.append(addStr);
			var btn = $("#addBtn_"+treeNode.id);
			if (btn) btn.bind("click", function(){
				window.parent.aduBox("<div><iframe scrolling='no' width='620' height='350' src='admin/exam!addExam.action?fid="+treeNode.id+"&type=0'></iframe></div>","添加题库",700,400);
				//var zTree = $.fn.zTree.getZTreeObj("treeDemo");
				//zTree.addNodes(treeNode, {id:(100 + newCount), pId:treeNode.id, name:"new node" + (newCount++)});
			});
		};
		function removeHoverDom(treeId, treeNode) {
			$("#addBtn_"+treeNode.id).unbind().remove();
		};

		$(document).ready(function(){
			$.fn.zTree.init($("#treeDemo"), setting);
		});
		//-->
	</SCRIPT>
<style type="text/css">
	.ztree li button.add {margin-left:2px; margin-right: -1px; background-position:-144px 0; vertical-align:top; *vertical-align:middle}
</style>
<div class="zTreeDemoBackground" style="float: left;width: 12%;overflow: auto;">
	<ul id="treeDemo" class="ztree"></ul>
</div>
<div style="float: right;width: 88%">
	<div id="crudList" class="${type.name}">
	    <div id="crudListSearch">
	        #{crud.search /}
	    </div>
	    <div id="crudListTable">
	   		#{crud.table fields:['booName','booDet','booIsbn','simage','boo_prti','booPuti','booPrintingTime','booWonu','booEdit','booPages','booImpr','booSeal','booMo','booBorr','booEnsh','booPin','booBarCode']}
	        #{/crud.table}
	    </div>
	    <div id="crudListPagination">
	        #{crud.pagination /}
	    </div>
	    <p id="crudListAdd">
	        <a href="@{blank()}">添加</a>
	    </p>
	</div>
</div>
<div style="clear: both;"></div>
